package com.swind.fast.modules.app.railway.permission.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.swind.fast.modules.app.railway.permission.entity.RailwayPermission;
import com.swind.fast.modules.app.railway.permission.service.IRailwayPermissionService;

import com.swind.fast.modules.app.railway.permission.vo.RailwayPermModel;

import com.swind.fast.common.api.vo.Result;
import com.swind.fast.common.system.query.QueryGenerator;
import com.swind.fast.common.util.oConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;
import java.util.HashMap;

@RestController
@RequestMapping("/app/railway/permission")
@Slf4j
public class RailwayPermissionController {

    @Autowired
    private IRailwayPermissionService railwayPermissionService;

    @GetMapping(value = "/list")
    public Result<IPage<RailwayPermission>> queryPageList(RailwayPermission railwayPermission,
                                      @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                      @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                      HttpServletRequest req) {

      QueryWrapper<RailwayPermission> queryWrapper = QueryGenerator.initQueryWrapper(railwayPermission, req.getParameterMap());
      Page<RailwayPermission> page = new Page<RailwayPermission>(pageNo, pageSize);
      IPage<RailwayPermission> pageList = railwayPermissionService.page(page, queryWrapper);
      return Result.OK(pageList);
    }

    @RequestMapping(value = "/queryAllPermItems", method = RequestMethod.GET)
    public Result<?> queryAllPermItems() {
      Map<String, List<RailwayPermModel>> res = new HashMap<String, List<RailwayPermModel>>();
      res = railwayPermissionService.queryAllPermItems();
      return Result.ok(res);
    }

}
